#include <REGX52.H>
#include "LCD1602.h"
#include "Key.h"
#include "Delay.h"
#include "AT24C02.h"

unsigned char KeyNum;
unsigned int Data;
void main(void)
{
	LCD_Init();
	LCD_ShowNum(1,1,Data,5);
	while(1)
	{
		KeyNum = Key();
		if (KeyNum == 1)
		{
			Data++;
			LCD_ShowNum(1,1,Data,5);
		}
		if (KeyNum == 2)
		{
			Data--;
			LCD_ShowNum(1,1,Data,5);
		}
		if (KeyNum == 3)
		{
			AT24C02_WriteByte(0,Data%256);
			Delay1ms(5);
			AT24C02_WriteByte(1,Data/256);
			Delay1ms(5);
			LCD_ShowString(2,1,"WRITE OK!");
			Delay1ms(1000);
			LCD_ShowString(2,1,"         ");
		}
		if (KeyNum == 4)
		{
			Data = AT24C02_ReadByte(0);
			Data |= AT24C02_ReadByte(1) << 8;
			LCD_ShowNum(1,1,Data,5);
			LCD_ShowString(2,1,"READ OK!");
			Delay1ms(1000);
			LCD_ShowString(2,1,"        ");
		}
	}
}